from fastapi import APIRouter, Query,UploadFile
from tortoise.expressions import Q

from app.settings import settings
from app.controllers.mini.settings import mini_settings_controller
from app.schemas.base import Success, SuccessExtra,Fail
from app.schemas.mini import *
from app.utils.upload import upload_image,upload_file
from typing import List

mini_settings_router = APIRouter()


@mini_settings_router.get("/list", summary="配置开关列表")
async def list_content(
        page: int = Query(1, description="页码"),
        page_size: int = Query(10, description="每页数量"),
        id: int = Query(None, description="页码"),
        vision: str = Query(None, description="小程序最新版本号"),
):
    q = Q()
    if id:
        q &= Q(id=id)
    if vision:
        q &= Q(set_value=vision)

    total, data = await mini_settings_controller.do_list(page=page, page_size=page_size, search=q)
    return SuccessExtra(data=data, total=total, page=page, page_size=page_size)

@mini_settings_router.post("/cos_path", summary="获取cos_path")
async def cos_path(
        cos_path_in:CosPath,
):

    data = cos_path_in.path.split(',')
    return SuccessExtra(data=data)
